<?php


namespace app\business\controller;


use app\admin\model\Admin;
use app\admin\model\Menulist;
use think\Controller;
use think\Cookie;

class Base extends Controller
{

    public function _initialize()
    {
        if(!Cookie::has('admin_id')){
            return $this->error('未登陆','admin/login/');
        }else{
            $admin = new Admin();
            $adminWhere['id'] = Cookie::get('admin_id');
            $adminInfo = $admin->getOne($adminWhere);
            $menu = new Menulist();
            if($adminInfo['show_menu_id'] != 'all'){
                $topWhere['id'] = array('in', $adminInfo['show_menu_id']);
            }else{
                $topWhere['pid'] = 0;
            }
            $topMenu = $menu->getAllMenu($topWhere);
            foreach($topMenu as $j=>$k){
                $secondWhere['pid'] = $k['id'];
                $secondMenu = $menu->getAllMenu($secondWhere);
                $k['secondMenu']= $secondMenu;
            }

            return $this->assign('topMenu',$topMenu);
        }
    }
}